
package pie.basic;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.data.general.DefaultPieDataset;

/**
 * 這是一個餅形統計圖(pie chart)的 sample code
 * 
 * @author Eric.Kao(gau168.gau@msa.hinet.net)
 * @version 1.0
 * @company E885 Group
 * @copyright Copyright (c) 2001-2008
 */

public class FirstPieChart
{
	private String section1 = "Category 1";

	private String section2 = "Category 2";

	private String section3 = "Category 3";

	public FirstPieChart()
	{
		// The Data:
		// JFreeChart can create pie charts using data from any class thant implements the PieDataset interface.
		// The DefaultPieDataset class provides a convenient implementation of the interface.
		DefaultPieDataset pieDataset = new DefaultPieDataset();
		pieDataset.setValue( section1, 43.2 );
		pieDataset.setValue( section2, 27.9 );
		pieDataset.setValue( section3, 79.5 );

		// Crate Pie Chart
		JFreeChart chart = ChartFactory.createPieChart( "sample chart", pieDataset, true, true, false );

		// Display Pie Chart
		ChartFrame frame = new ChartFrame( "Test", chart );
		frame.pack();
		frame.setVisible( true );
	}

	/**
	 * @param args
	 */
	public static void main( String[] args )
	{
		new FirstPieChart();
	}

}
